package cn.iocoder.springboot.lab12.mybatis.controller;

import cn.iocoder.springboot.lab12.mybatis.dataobject.UserDO;
import cn.iocoder.springboot.lab12.mybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/")
public class DemoController {

    @Autowired
    private UserMapper userMapper;


    @GetMapping("/test")
    @Transactional(rollbackFor = Exception.class)
    public void test() {
        System.out.println("开始");
        System.out.println("插入测试1");
        UserDO user = new UserDO().setUsername("11")
                .setPassword("11").setCreateTime(new Date());
        userMapper.insert(user);


        System.out.println("插入测试2");
        user = new UserDO().setUsername("22")
                .setPassword("22").setCreateTime(new Date());
        userMapper.insert(user);

        throw new RuntimeException("异常");
    }

}
